{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cartopy - [1] base info\n",
    "#\n",
    "# https://blog.csdn.net/m0_53156691/article/details/123792063\n",
    "#\n",
    "# https://scitools.org.uk/cartopy/docs/latest/gallery/index.html\n",
    "#\n",
    "# https://www.naturalearthdata.com/\n",
    "# https://naciscdn.org/naturalearth/packages/natural_earth_vector.zip\n",
    "#\n",
    "import os\n",
    "import tempfile\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import cartopy\n",
    "import cartopy.crs as ccrs\n",
    "import cartopy.feature as cfeature\n",
    "\n",
    "\n",
    "print(cartopy.__version__)\n",
    "print('data_dir                 = ', cartopy.config['data_dir'])\n",
    "print('cache_dir                = ', cartopy.config['cache_dir'])\n",
    "print('repo_data_dir            = ', cartopy.config['repo_data_dir'])\n",
    "print('pre_existing_data_dir    = ', cartopy.config['pre_existing_data_dir'])\n",
    "print('downloaders              = ', cartopy.config['downloaders'])\n",
    "\n",
    "# data_dir                 =  C:\\Users\\shenyc\\.local\\share\\cartopy\n",
    "# cache_dir                =  C:\\Users\\shenyc\\AppData\\Local\\Temp\\cartopy_cache_dir\n",
    "# repo_data_dir            =  d:\\Programs\\Python39\\lib\\site-packages\\cartopy\\data\n",
    "# pre_existing_data_dir    =  E:\\sfxData\\Map\\natural_earth_vector\n",
    "# downloaders              =  {\n",
    "#       ('shapefiles', 'natural_earth'): < cartopy.io.shapereader.NEShpDownloader object at 0x00000169B82E6910 > ,\n",
    "#       ('shapefiles', 'gshhs'): < cartopy.io.shapereader.GSHHSShpDownloader object at 0x00000169B82E6DC0 > }\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cartopy - [2] crs (coordinate reference system) 坐标参考系\n",
    "# \n",
    "import cartopy.crs\n",
    "\n",
    "print('PlateCarree  = ', cartopy.crs.PlateCarree())\n",
    "print('AlbersEqualArea  = ', cartopy.crs.AlbersEqualArea())\n",
    "print('AlbersEqualArea  = ', cartopy.crs.AzimuthalEquidistant())\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cartopy - [3] 加载空间数据\n",
    "#\n",
    "import cartopy.crs as ccrs\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "fig = plt.figure(figsize=(8, 6))\n",
    "\n",
    "# \n",
    "crs = ccrs.PlateCarree()\n",
    "ax = fig.add_subplot(3, 1, 1, projection=crs)   # GeoAxes\n",
    "ax.stock_img()\n",
    "\n",
    "# \n",
    "crs = ccrs.AlbersEqualArea()\n",
    "ax = fig.add_subplot(3, 1, 2, projection=crs)   # GeoAxes\n",
    "ax.stock_img()\n",
    "\n",
    "#\n",
    "crs = ccrs.PlateCarree()\n",
    "ax = fig.add_subplot(3, 1, 3, projection=crs)\n",
    "ax.stock_img()\n",
    "# ax.coastlines() # error\n",
    "\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cartopy - [4] 利用shape矢量数据来加载地理坐标系下的中国国界图\n",
    "#\n",
    "import cartopy.crs as ccrs\n",
    "import matplotlib.pyplot as plt\n",
    "import cartopy.io.shapereader as sr\n",
    "\n",
    "fig = plt.figure()\n",
    "# -----------------------------------------------------\n",
    "crs = ccrs.PlateCarree()\n",
    "geom = sr.Reader(r\"E:\\sfxData\\Map\\china-shapefiles\\china.shp\").geometries()\n",
    "ax = fig.add_subplot(1, 1, 1, projection=crs)\n",
    "# ax.stock_img()\n",
    "ax.add_geometries(geom, crs)\n",
    "# ax.set_extent([70, 140, 0, 60], crs)\n",
    "# -----------------------------------------------------\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import cartopy.crs as ccrs\n",
    "\n",
    "box = [40, 180, 0, 90]\n",
    "ax = plt.axes(projection=ccrs.PlateCarree())\n",
    "# ax.set_extent(box, ccrs.PlateCarree())\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
